define(["jquery", "easy-admin", 'miniTab'], function ($, ea, miniTab) {

    var init = {
        index_url: '/manage/member/miniapp/my/index',
    };

    var Controller = {
        index: function () {
            ea.request.get(
                {
                    url: init.index_url,
                    data: {},
                }, function (res) {
                    var list = res.data.data.list;

                    var html = '';
                    list.forEach(v => {
                        html += '<tr><td>' + v.id + '</td><td>' + v.appname + '</td><td>' + v.service_id + '</td><td>' + v.create_time + '</td><td><button type="button" class="layui-btn layui-btn-xs layui-btn-normal" data-id="'+ v.id +'">管理应用</button></td></tr>';
                    });
                    $('#my-miniapp').html(html);
                }
            );

            $('body').off('click', '[data-id]').on('click', '[data-id]', function (event){
                //给页面manage/member/index发信号，重新渲染菜单并打开关于应用页面
                var evt = new Event("addAppMenu");//创建一个事件对象
                evt.miniapp_id = $(this).attr('data-id');//获取应用ID
                parent.document.dispatchEvent(evt);//发送信号

                setTimeout(function () {
                    // 打开新的窗口
                    miniTab.openNewTabByIframe({
                        href:"/manage/member.setting/index?miniapp_id=" + evt.miniapp_id,
                        title:"关于应用",
                    });
                }, 500);
            })

            ea.listen();
        },
        add: function () {
            ea.listen();
        },
        edit: function () {
            ea.listen();
        },
    };
    return Controller;
});